-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add more properties controlling service reference code generation #10641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
RebaseOutputs="true" | ||
RemoveProperties="%(ProjectReferenceWithConfiguration.GlobalPropertiesToRemove);TargetFrameworks;RuntimeIdentifier"> | ||
RemoveProperties="Configuration;Platform;RuntimeIdentifier;TargetFramework;TargetFrameworks"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainersigwald is removing these properties sufficient?
And, am I missing something important in the shift from @(ProjectReferenceWithConfiguration)
to using @(OpenApiProjectReference)
items directly? (Without this, design-time builds would still have been broken and '$(OpenApiBuildReferencedProjects)' == 'false'
would not work.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd definitely want to keep something like %(OpenApiProjectReference.GlobalPropertiesToRemove)
in there as an escape hatch. This list looks ok to me, but there's always a risk of things changing (like when multitargeting was added) or user projects having their own custom dimensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! I added this to #4923 because I have other bits to do short-term.
@natemcmaster I'd of course appreciate any input you have on the MSBuild changes |
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" /> | ||
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" /> | ||
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" /> | ||
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" /> | ||
|
||
<!-- | ||
Settings users may update as they see fit. | ||
--> | ||
<PropertyGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glennc do you have any input on the names of these user-visible properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I wouldn't block on any of my comments.
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" | ||
AfterTargets="ResolveProjectReferences" | ||
Condition="'$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true'"> | ||
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" DependsOnTargets="ResolveProjectReferences"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have Condition="@(OpenApiProjectReference->Count()) != 0"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really doesn't matter because everything in this target no-ops when there's nothing worth doing. Let me know if you feel differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple is better, I agree with Doug.
.../Extensions.ApiDescription.Client/src/build/Microsoft.Extensions.ApiDescription.Client.props
Outdated
Show resolved
Hide resolved
</Target> | ||
|
||
<Target Name="_TieInGenerateOpenApiReferenceCode" | ||
BeforeTargets="BeforeCompile" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be CoreCompile
. Would that allow users to do user things ™️ in BeforeCompile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoreCompile
is late because it comes after the MSBuild targets cache the list of references and source files involved in the compilation
Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_ApiDescriptionClientAssemblyTarget> | ||
<_ApiDescriptionClientAssemblyTarget | ||
Condition="'$(MSBuildRuntimeType)' != 'Core'">net461</_ApiDescriptionClientAssemblyTarget> | ||
<_ApiDescriptionClientAssemblyPath>$(MSBuildThisFileDirectory)/../tasks/$(_ApiDescriptionClientAssemblyTarget)/Microsoft.Extensions.ApiDescription.Client.dll</_ApiDescriptionClientAssemblyPath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really relevant anymore? MSBuild supports netstandard2.0 everywhere .NET Core runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the assembly has any dependencies that aren't in netstandard as implemented in .NET 4.7.2, I'd leave this in. Netstandard task assemblies are probably much more viable now that VS is on 4.7.2, but they've historically been a problem and splitting into core and full implementations has been required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mentioning it because we've been doing ns2.0 in Razor for a while now with no problems.
Since this is new code it should be fine as long as we test it in VS right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, as long as it works in VS, command line msbuild.exe, and command line msbuild.exe from a Build Tools install of VS, you should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this to #4923 since the extra bits do no harm. This is all an implementation detail and it'll take time to do the necessary testing…
@@ -8,7 +8,7 @@ | |||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Identity.Specification.Tests" ProjectPath="$(RepoRoot)src\Identity\Specification.Tests\src\Microsoft.AspNetCore.Identity.Specification.Tests.csproj" /> | |||
<ProjectReferenceProvider Include="Microsoft.Web.Xdt.Extensions" ProjectPath="$(RepoRoot)src\SiteExtensions\Microsoft.Web.Xdt.Extensions\src\Microsoft.Web.Xdt.Extensions.csproj" /> | |||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" ProjectPath="$(RepoRoot)src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj" /> | |||
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Tasks" ProjectPath="$(RepoRoot)src\Mvc\Extensions.ApiDescription.Client\src\Microsoft.Extensions.ApiDescription.Client.csproj" /> | |||
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Client" ProjectPath="$(RepoRoot)src\Mvc\Extensions.ApiDescription.Client\src\Microsoft.Extensions.ApiDescription.Client.csproj" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing some necessary context here, but I don't really get the point of renaming an assembly containing tasks to not be suffixed with .Tasks
.
Is the metapoint here that we want to separate the tasks used for client-gen from the tasks used inside server-projects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my original point but I ended up not needing tasks in the server project and decided I preferred using the same name everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some minor comments here but nothing blocking.
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" /> | ||
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" /> | ||
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" /> | ||
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random observation: GetCurrentItems
is a pretty generic name given that item
is a common term in MSBuild. We might want to choose more specific names. I don't think GetFileReferenceMetadata
is bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the suggestion to #4923
<!-- | ||
Options added to the code generator command line by default. Provides the default %(Options) metadata of | ||
@(OpenApiReference) and @(OpenApiProjectReference) items. | ||
--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always really happy to see quality docs in MSBuild 👍
|
||
<!-- | ||
If 'true' (the default), generate code for @(OpenApiReference) and @(OpenApiProjectReference) items during | ||
design-time builds. Otherwise, generate code only during a full build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going with the name OpenApiGenerateCodeOnBuild
would this become OpenApiGenerateCodeOnDesignTimeBuild
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about it but the sense is a bit different. @glennc and I decided this one was fine as-is. Could of course change it if users disagree.
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" | ||
AfterTargets="ResolveProjectReferences" | ||
Condition="'$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true'"> | ||
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" DependsOnTargets="ResolveProjectReferences"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple is better, I agree with Doug.
@@ -85,10 +79,9 @@ | |||
Condition="$(OpenApiGenerateAtDesignTime) OR ('$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true')" | |||
Inputs="@(OpenApiReference)" | |||
Outputs="%(OutputPath)"> | |||
<MSBuild BuildInParallel="$(BuildInParallel)" | |||
Projects="$(MSBuildProjectFullPath)" | |||
<MSBuild Projects="$(MSBuildProjectFullPath)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this idea with this call that we only want to call this once even with multi-targeting? If that's the case should we have a comment?
Basically I'm not sure why this is a separate invocation of MSBuild, a comment would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is about running things once. And, sure, I'll add a comment
25778bb
to
154deaa
Compare
154deaa
to
35c789a
Compare
- `$(OpenApiGenerateBeforeCompile)` controls if targets run before compile targets - #4924 - also correct multiple invocations when project has multiple target frameworks - `$(OpenApiBuildReferencedProjects)` controls whether `@(OpenApiProjectReference)` items build automatically - #6582 also: - add symbols for Microsoft.Extensions.ApiDescription.Client task assembly - #10508 - unconditionally run `OpenApiGetDocuments` target in referenced projects - corrects compilation in design-time builds - no longer uses `@(ProjectReferenceWithConfiguration)`; referenced project chooses all property values nits: - don't remove `$(TargetFrameworks)` when invoking `OpenApiGetDocuments` target (not necessary) - consolidate into a single `$(GenerateOpenApiReferenceCodeDependsOn)` property - rename task assembly and namespaces in Microsoft.Extensions.ApiDesription.Client to match the project - allow `OpenApiGetDocuments` targets to run in parallel if `$(BuildInParallel)` is enabled - remove `$(OpenApiDefaultOutputDirectory)` normalization; never concatenated with anything else - remove dangling `GenerateServiceFileReferenceCode` names
- make it clear these properties control code generation - use "OnBuild" for consistency with properties elsewhere in ASP.NET Core - remove "Default" from a comple of property names because commaents are pretty clear - rename a few targets for consistency with the new properties - word "Reference" didn't add much
…cription.Client.targets
35c789a
to
f1f5f2f
Compare
$(OpenApiGenerateBeforeCompile)
controls if targets run before compile targets$(OpenApiBuildReferencedProjects)
controls whether@(OpenApiProjectReference)
items build automaticallyalso:
OpenApiGetDocuments
target in referenced projects@(ProjectReferenceWithConfiguration)
; referenced project chooses all property valuesnits:
$(TargetFrameworks)
when invokingOpenApiGetDocuments
target (not necessary)$(GenerateOpenApiReferenceCodeDependsOn)
propertyOpenApiGetDocuments
targets to run in parallel if$(BuildInParallel)
is enabled$(OpenApiDefaultOutputDirectory)
normalization; never concatenated with anything elseGenerateServiceFileReferenceCode
names